package com.kgc.springboot.hangduo.service.impl;

import com.kgc.springboot.hangduo.mapper.UserMapper;
import com.kgc.springboot.hangduo.pojo.User;
import com.kgc.springboot.hangduo.pojo.UserExample;
import com.kgc.springboot.hangduo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: ASUS
 * @date: 2020/12/22 20:33
 * @description:
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User login(String phone, String password) {
        UserExample userExample = new UserExample();
        userExample.createCriteria().andPhoneEqualTo(phone).andPasswordEqualTo(password);
        List<User> users = userMapper.selectByExample(userExample);
        if(users.size()>0){
            return users.get(0);
        }
        return null;
    }

    @Override
    public int updateByUser(User user) {
        return userMapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public User selectById(Integer id) {
        return userMapper.selectByPrimaryKey(id);
    }
}
